//
//  MBMessageViewModel.m
//  MemberBusiness-ios
//
//  Created by cherry pu on 2018/4/25.
//  Copyright © 2018年 zhangXin. All rights reserved.
//

#import "MBMessageViewModel.h"
#import "MBHomeNetTool.h"
#import "MBMessageModel.h"
#import "MBMessageTableCellViewModel.h"

@implementation MBMessageViewModel

-(void)sendRequest:(MBRequestResult)result
{
    MBLoginUserModel* userModel = [MBLoginUserModelArchieveTool userInfoUnAchieveFromFile];
    MBSellerGoodsParam* param = [[MBSellerGoodsParam alloc]init];
    param.store_id = userModel.store_id;
    param.p = self.currentPage;
    param.token = userModel.token;
    [MBHomeNetTool homeNetToolSellerMessageWithParam:param success:^(MBHTTPResponse *response) {
        if (response.status == 1) {
            NSArray* array = response.result;
            NSMutableArray* list = [NSMutableArray array];
            
            for (int i=0; i<array.count; i++) {
                MBMessageModel* messageModel = [MBMessageModel yy_modelWithDictionary:array[i]];
                [list addObject:messageModel];
            }
            [self factoryInitDataModelArray:list totalCount:10 cellViewModelClass:[MBMessageTableCellViewModel class]];
            result(YES);
        }else {
            [InterfaceHUD showErrorHUDWithString:response.msg];
            result(NO);
        }
     } failure:^(NSError *error) {
         [InterfaceHUD showErrorHUDWithString:@"获取商品失败，请稍后重试！"];
         result(NO);
     }];
}

- (NSInteger)numberOfRowInSection:(NSInteger)section
{
    return 1;
}

-(NSInteger)numberOfSections
{
    return self.dataArray.count;
}

- (MBBaseTableCellViewModel *)cellViewModelForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return self.dataArray[indexPath.section];
}

- (CGFloat)heightForHeaderInSection:(NSInteger)section
{
    return [UIView lf_sizeFromIphone6:12];
}


@end
